package com.example.demo.dao;

import com.example.demo.model.ArticleInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/* @Author      zouzh
 * @PackageName BlogSystem-sm
 * @Package     com.example.demo.dao
 * @Date        2023/9/6 10:10
 */

@Mapper
public interface ArticleMapper {

    @Select("select * from blog where uid = #{uid} order by id desc")
    public List<ArticleInfo> getListByUid(@Param("uid")int uid);
    @Delete("delete from blog where id = #{id} and uid = #{uid}")
    public int delByAid(@Param("id") Integer id, int uid);
    @Insert("insert into blog(title, content, uid) values (#{title}, #{content}, #{uid})")
    public int add(ArticleInfo articleInfo);
    @Select("select * from blog where id = #{id} and uid = #{uid}")
    public ArticleInfo getArticleByIdAndUid(@Param("id") int id, @Param("uid") int uid);
    @Update("update blog set title = #{title}, content = #{content} where id = #{id} and uid = #{uid}")
    public int update(ArticleInfo articleInfo);
    @Select("select * from blog where id = #{aid}")
     public ArticleInfo getDetailById(@Param("aid") int aid);
    @Select("select count(*) from blog where uid = #{uid}")
    public int getArtCountByUid(@Param("uid") int uid);
    @Update("update blog set rcount = rcount + 1 where  id = #{aid}")
    public int updateRCount(@Param("aid") int aid);
    @Select("select * from blog order by id desc limit #{psize} offset #{offset}")
    public List<ArticleInfo> getListByPage(@Param("psize") int psize, @Param("offset") int offset);

    @Select("select count(*) from blog")
    public int getCount();
}
